home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_05 / tsai / pwhile.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-01  |  1.3 KB  |  61 lines

  1.  
  2. Listing 10: Function Pwhile::parse()
  3.  
  4. _CLASSDEF(Pwhile)
  5. class _CLASSTYPE Pwhile
  6. {
  7. public:
  8.   Pwhile(){}
  9.   ~Pwhile(){}
  10.   BOOL parse();
  11.   int write(int,const char *);
  12. }
  13.  
  14. BOOL Pwhile::parse()
  15. {
  16.   int nEndofWhile;
  17.   Token * pTemp;
  18.  
  19.   // create an expression object
  20.   Pexpression * pTempExpression = new Pexpression;
  21.   // call function parse and clean up
  22.   PARSEU(pTempExpression)
  23.   pTemp = gpTokenizer->getToken();    // get a new token
  24.  
  25.   if (pTemp->tokentype == tkdo)       // check for token DO
  26.   {
  27.     pTemp = gpTokenizer->peekToken(); // a look ahead token
  28.  
  29.     // a loop to parse statements inside the while loop
  30.     while ((pTemp->tokentype != tkendwhile) &&
  31.    (!gpTokenizer->eof()) )
  32.     {
  33.          // create a statement object
  34.          Pstatement * pMyStatement = new Pstatement;
  35.          PARSEU(pMyStatement)   // call function parse and clean up
  36.  
  37.  pTemp = gpTokenizer->peekToken();
  38.     }
  39.  
  40.     if (pTemp->tokentype == tkendwhile)
  41.     {
  42.      // update the branch pointer
  43.       gpLocalSymTable->Put(nEndofWhile,
  44.                            new Sym_Number((NUMBER) gnCslFileIndex));
  45.       gpTokenizer->getToken();
  46.     }
  47.     else
  48.     {
  49.        gpErrorFile->raise(39);
  50.        return FALSE;
  51.     }
  52.   }
  53.   else
  54.   {
  55.      gpErrorFile->raise(10);
  56.      return FALSE;
  57.   }
  58.  
  59.   return TRUE;
  60. }
  61.